import { ajax, tools } from '../../js/ajax.js';

let txtName = document.getElementById('txtName');
let txtPwd = document.getElementById('txtPwd');
let txtPwd2 = document.getElementById('txtPwd2');
let txtNickname = document.getElementById('txtNickname');
let btnReg = document.getElementById('btnReg');
let spInfo = document.getElementById('spInfo');

btnReg.addEventListener('click', () => {
  spInfo.innerHTML = '';
  let pwd = txtPwd.value;
  let pwd2 = txtPwd2.value;
  if (pwd.trim() == '') {
    spInfo.innerHTML = '密码不能为空';
    return;
  }
  if (pwd != pwd2) {
    spInfo.innerHTML = '密码不一致';
    return;
  }
  // 注册
  let user = {
    username: txtName.value,
    password: tools.md5(pwd),
    nickname: txtNickname.value,
  };

  ajax.post('/user/auth/reg', user, (data) => {
    spInfo.innerHTML = data.message;
  });
});
